package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目相关接口")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页查询, 带条件,护理项目
     *
     * @param pageNum
     * @param pageSize
     * @param name
     * @param status
     * @return
     */
    @GetMapping
    @ApiOperation(value = "条件分页查询护理计划", notes = "传入分页条件")
    public ResponseResult<NursingProjectVo> findByPage(
            @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "name", required = false) String name,
            @RequestParam(name = "status", required = false) Integer status) {
        PageResponse<NursingProjectVo> responseResult = nursingProjectService.findByPage(pageNum, pageSize, name, status);
        return success(responseResult);
    }

    /**
     * 创建护理项目
     *
     * @param nursingProjectDto
     * @return
     */
    @PostMapping
    @ApiOperation(value = "新增护理计划", notes = "传入新增信息")
    public ResponseResult createNursingProject(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.createNursingProject(nursingProjectDto);
        return success();
    }

    /**
     * 根据id查询护理项目
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id进行查询", notes = "传入查询id")
    public ResponseResult<NursingProjectVo> findById(@PathVariable(name = "id") Long id) {
        NursingProjectVo nursingProjectvo = nursingProjectService.findById(id);
        return success(nursingProjectvo);
    }

    /**
     * 更新护理项目
     *
     * @param nursingProjectDto
     * @return
     */
    @PutMapping
    @ApiOperation(value = "根据id进行修改", notes = "传入修改信息")
    public ResponseResult updateNursingProject(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.updateNursingProject(nursingProjectDto);
        return success();
    }

    /**
     * 更新状态
     *
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "根据id进行启用禁用", notes = "传入修改状态信息")
    public ResponseResult updateStatus(@PathVariable(name = "id") Long id, @PathVariable(name = "status") Integer status) {
        nursingProjectService.updateStatus(id, status);
        return success();
    }

    /**
     * 根据id删除护理项目
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id进行删除", notes = "传入删除id")
    public ResponseResult deleteById(@PathVariable(name = "id") Long id) {
        nursingProjectService.deleteNursingProject(id);
        return success();
    }

    /**
     * 查询所有
     *
     * @return
     */
    @GetMapping("/all")
    @ApiOperation(value = "查询所有", notes = "无")
    public ResponseResult<List<NursingProjectVo>> findAll() {
        List<NursingProjectVo> success = nursingProjectService.findAll();
        return success(success);
    }
}
